
import { Effect, Reducer } from 'umi';
import {message} from "antd"
import { GetOrder } from '@/services';
import { Iorder } from '@/types';
export interface OrderModelState {
    orderData: Iorder[];
    total:number;
}
export interface OrderModelType {
    namespace: 'order_order';
    state: OrderModelState;
    effects: {
      GetOrder: Effect;
    };
    reducers: {
        save: Reducer<OrderModelState>;
    };
}
const OrderModel: OrderModelType = {
    namespace: 'order_order',
    state: {
      orderData: [],
      total:0
    },
    effects: {
        *GetOrder({ payload }, { call, put }) {
            let result = yield call(GetOrder,payload);
            if (result) {
                yield put({
                    type: 'save',
                    payload: {
                      orderData:result.records.map((item:Iorder)=>{
                         let str=["待付款","待发货","待收货","待评价","成功","失败"]
                         let index=[1,2,3,4,5,6].findIndex(items=>items==item.status)
                         item.statusStr=str[index!]
                        return item
                      }),
                      total:result.total
                    }
                })
            }
        },
    },
    reducers: {
        save(state, action) {
            return {
                ...state,
                ...action.payload,
            };
        },
    },
};

export default OrderModel;


